package com.movie.modules.jf.controller;

import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import com.movie.modules.jf.entity.NewsEntity;
import com.movie.modules.jf.service.NewsService;
import com.movie.common.utils.PageUtils;
import com.movie.common.utils.R;



/**
 * 新闻表
 *
 * @author kakarot
 * @email 532050892@qq.com
 * @date 2021-08-20 01:31:10
 */
@RestController
@RequestMapping("/sys/news")
@Api(tags = "新闻接口")
public class NewsController {
    @Autowired
    private NewsService newsService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation("新闻列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = newsService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{newsId}")
    @ApiOperation("新闻详情")
    public R info(@PathVariable("newsId") Integer newsId){
        return R.ok().put("data", newsService.getInfoById(newsId));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("添加/修改新闻")
    public R update(@RequestBody NewsEntity news){
		newsService.update(news);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{newsId}")
    @ApiOperation("删除信息")
    public R delete(@PathVariable("newsId") Integer newsId){
        newsService.delete(newsId);
        return R.ok();
    }

    @PostMapping("/status")
    @ApiOperation("更改新闻状态")
    public R status(@RequestBody NewsEntity news){
        newsService.updateById(news);
        return R.ok();
    }

}
